import { createStore } from 'vuex'
const store = createStore({
  state() {
    return {
      count: 0,
    }
  },
  mutations: {
    increment(state, payload = 1) {
      state.count += payload
    },
    decrement(state, payload = 1) {
      state.count -= payload
    },
  },
  // 直接调用action,再去修改mutations，再去修改state
  actions: {
    incrementAction(context, payload) {
      context.commit('increment', payload)
    },
    decrementAction(context, payload) {
      context.commit('decrement', payload)
    },
    newPromoseActions(context) {
      // action可以返回promise
      return new Promise((res, rej) => {
        setTimeout(() => {
          res('成功')
          // rej('失败')
        }, 1000)
      })
    },
  },
})
export default store
